from typing import Any

import requests
from dify_plugin import ToolProvider


class Html2pdfProvider(ToolProvider):
    def _validate_credentials(self, credentials: dict[str, Any]) -> None:
        gotenberg_url = credentials.get("gotenberg_url", "https://demo.gotenberg.dev")
        if not gotenberg_url:
            raise ValueError("Gotenberg URL is required")
        try:
            response = requests.get(gotenberg_url)
            if response.status_code != 200:
                raise ValueError("Gotenberg URL is not valid")
        except Exception as e:
            raise ValueError(f"Gotenberg URL is not valid: {e}")